<template>
  <img :src="app.icon" class="app-img" alt="" @click.stop="dialogVisible = true">
  <IDialog title="舔狗日记" :visible="dialogVisible" @ok="dialogVisible = false" @cancel="dialogVisible = false">
    <div class="tiangou">
      <img src="https://z1.ax1x.com/2023/11/20/piUaYCT.jpg" alt="">
      <div class="text">
        <p>宝</p>
        <p>{{ tiangou }}</p>
      </div>
      <button title="继续舔" @click="getTiangou"></button>
      <p class="copy" :class="{copied: copied}" @click="handleCopy(tiangou)">{{ copied ? "已复制" : "点击复制" }}</p>
    </div>
  </IDialog>
</template>

<script setup>
import { ref, watch } from 'vue';
import axios from 'axios';
import { useClipboard } from "@vueuse/core";
const props = defineProps({
  app: {
    type: Object,
    default: () => {},
  }
})

const dialogVisible = ref(false);
const tiangou = ref("");
const getTiangou = () => {
  axios.get('https://api.moyuduck.com/tiangou').then(res => {
    tiangou.value = res.data.data;
  })
}

getTiangou();

const { copy: handleCopy, copied } = useClipboard({ tiangou });
</script>

<style lang="less" scoped>
.tiangou {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  img {
    height: 120px;
  }
  .text {
    margin: 20px 40px;
    user-select: text;
    p {
      line-height: 2;
      text-align: justify;
      // text-align-last: center;
      &:nth-of-type(1) {
        text-align: center;
      }
    }
  }
  button {
    border: 0;
    margin: 0 0.3rem;
    padding: 0;
    width: 60px;
    height: 60px;
    color: transparent;
    border-radius: 100%;
    background-image: url();
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: no-repeat;
    box-shadow: 0 0 0.2rem rgba(0, 21, 110, .1);
    cursor: pointer;
    outline: 0;
    &:hover {
      box-shadow: 0 0 1.2rem var(--primary-color);
    }
  }
  .copy {
    position: absolute;
    right: 24px;
    bottom: 20px;
    cursor: pointer;
    &.copied {
      color: #389e0d !important;
    }
    &:hover {
      color: var(--primary-color);
    }
  }
}
</style>